
<template>
<div style="width: 430px;height: 932px;">
  <van-nav-bar
    title=""
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  />
  <van-tabs v-model="active">
    <van-tab title="全部">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.aid==user.id">
          <p>
            订单号：{{item.id}}
            <span v-show="item.status==0&item.aid==user.id">|已评价</span>
            <span v-show="item.status==1&item.aid==user.id">|待付款</span>
            <span v-show="item.status==2&item.aid==user.id">|待发货</span>
            <span v-show="item.status==3&item.aid==user.id">|待收货</span>
            <span v-show="item.status==4&item.aid==user.id">|待评价</span>
            <span v-show="item.status==5&item.aid==user.id" @click="todelete(item.id)">|已取消</span>
          </p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
          <p>
            <van-button v-show="item.status==1&item.aid==user.id" @click="tofukuan(item.id)">付款</van-button>
            <van-button v-show="item.status==1&item.aid==user.id" @click="toquxiao(item.id)">取消订单</van-button>
            <van-button v-show="item.status==2&item.aid==user.id" @click="toXQ(item.id)">查看订单</van-button>
            <van-button v-show="item.status==4&item.aid==user.id" @click="topingjia(item.id)">评价</van-button>
            <van-button v-show="item.status==5&item.aid==user.id" @click="todelete(item.id)">删除订单</van-button>
          </p>
        </van-cell>
      </van-list>
    </van-tab>
    <van-tab title="待付款">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.status==1&item.aid==user.id">
          <p>订单号：{{item.id}}</p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
          <p><van-button @click="toquxiao(item.id)">取消订单</van-button><van-button @click="tofukuan(item.id)">付款</van-button></p>
        </van-cell>
      </van-list>
    </van-tab>
    <van-tab title="待发货">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.status==2&item.aid==user.id">
          <p>订单号：{{item.id}}</p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
          <p><van-button @click="toXQ(item.id)">查看订单</van-button></p>
        </van-cell>
      </van-list>
    </van-tab>
    <van-tab title="待收货">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.status==3&item.aid==user.id">
          <p>订单号：{{item.id}}</p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
        </van-cell>
      </van-list>
    </van-tab>
    <van-tab title="待评价">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.status==4&item.aid==user.id">
          <p>订单号：{{item.id}}</p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
          <p><van-button @click="topingjia(item.id)">评价</van-button></p>
        </van-cell>
      </van-list>
    </van-tab>
    <van-tab title="已取消">
      <van-list>
        <van-cell v-for="(item, index) in shoppingList" :key="index" v-show="item.status==5&item.aid==user.id">
          <p>订单号：{{item.id}}</p>
          <p>商品名称：{{item.comname}}  <span>￥{{item.price}}x{{item.number}}</span></p>
          <p>规格：{{item.details}}</p>
          <p>总价：￥{{item.priceorder}}</p>
          <p><van-button @click="todelete(item.id)">删除订单</van-button></p>
        </van-cell>
      </van-list>
    </van-tab>
  </van-tabs>
</div>
</template>

<script>
import axios from "axios";

export default {
  data () {
    return {
      user:{},
      active: 0,
      shoppingList:[],
      shoppingId:'',
      pingjiaId:'',
      form: {},
      payId:'',
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    generateRandomNumber() {
      return Math.floor(Math.random() * 9000000000) + 1000000000;
    },
    tofukuan(id){
      this.payId = id;
      this.$router.push({
        path: '/paymentpage',
        query: {
          id: this.payId
        }
      })
      localStorage.setItem("payId",this.payId)
    },
    topingjia(id){
      this.pingjiaId = id;
      this.$router.push({
        path: '/evaluate',
        query: {
          id: this.pingjiaId
        }
      })
      localStorage.setItem("pingjiaId",this.pingjiaId)
    },
    toXQ(id){
      this.shoppingId = id;
      this.$router.push({
        path: '/shoppingdetails',
        query: {
          id: this.shoppingId
        }
      })
      localStorage.setItem("shoppingId",this.shoppingId)
    },
    todelete(id){
      axios.post("/shoppingorder/deleteorder?id="+id).then(res=>{
        this.$toast("删除成功");
        this.findShoppingOrder();
      })
    },
    toquxiao(id){
      axios.post("/shoppingorder/cancelorder?id="+id).then(res=>{
        this.$toast("取消成功");
        this.findShoppingOrder();
      })
    },
    findShoppingOrder(){
      axios.post("/shoppingorder/findShoppingOrder",this.form).then(res=>{
        this.shoppingList = res.data.data.list;
      })
    }
  },
  created() {
    this.findShoppingOrder();
    localStorage.setItem("orers",this.generateRandomNumber());
    this.user = JSON.parse(localStorage.getItem('admin'));
  }
}
</script>


<style scoped>

</style>
